Skip to content

test: integration coverage, mock client, 80% thresholds#34

Merged
PAMulligan merged 1 commit into
mainfrom
14-unit-and-integration-tests-coverage
May 8, 2026
Merged

test: integration coverage, mock client, 80% thresholds#34
PAMulligan merged 1 commit into
mainfrom
14-unit-and-integration-tests-coverage

Conversation

@PAMulligan
Copy link
Copy Markdown
Contributor

Closes #14

Summary

  • Wire @vitest/coverage-v8 with a global 80% threshold across statements/branches/functions/lines and a new pnpm test:coverage script.
  • Introduce a typed MockChatApiClient (src/test-utils/MockChatApiClient.ts) with FIFO mockReply/mockError/mockTimeout/mockNetworkError/mockPending helpers and call-history inspection. Self-tested in src/test-utils/__tests__/.
  • Add src/__tests__/chatFlow.integration.test.tsx exercising the full flow against the real ChatWidget: open → typing indicator → assistant reply, sources rendering, network-error → inline Retry → recovery, non-recoverable validation error hides Retry, and sessionStorage persistence across remounts.
  • Close coverage gaps: theme="auto" matchMedia subscription and the full translation-routing matrix in useChat (TIMEOUT, NETWORK_ERROR, both RATE_LIMITED paths, unknown-code fallback).

Coverage

Metric Before After
Statements 91.49% 94.71%
Branches 82.38% 87.42%
Functions 96.55% 97.70%
Lines 94.48% 97.49%

184 tests passing (was 167).

Test plan

  • pnpm test:coverage — 184/184 pass, all four thresholds satisfied
  • pnpm exec tsc --noEmit clean
  • Manual: confirm coverage/ html report renders the same numbers as the CLI table

🤖 Generated with Claude Code

- Add @vitest/coverage-v8 with global 80% statement/branch/function/line
  thresholds (vite.config.ts) and a `pnpm test:coverage` script.
- Introduce src/test-utils/MockChatApiClient: typed FIFO mock for
  ChatApiClient with mockReply/mockError/mockTimeout/mockNetworkError/
  mockPending helpers and call-history inspection.
- Add src/__tests__/chatFlow.integration.test.tsx covering the full chat
  flow against the real ChatWidget: open → typing indicator → assistant
  reply, sources rendering, network-error → inline Retry → recovery,
  non-recoverable validation error hides Retry, and sessionStorage
  persistence across remounts.
- Fill coverage gaps: theme=auto matchMedia subscription and the full
  translation-routing matrix in useChat (TIMEOUT, NETWORK_ERROR, both
  RATE_LIMITED paths, unknown codes).

Aggregate coverage now 94.71% / 87.42% / 97.70% / 97.49%
(stmts / branches / functions / lines), 184 tests passing.

Closes #14

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages
Copy link
Copy Markdown

Deploying chat-widget with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1c745a2
Status: ✅  Deploy successful!
Preview URL: https://8e747bc4.chat-widget-ejc.pages.dev
Branch Preview URL: https://14-unit-and-integration-test-9w3a.chat-widget-ejc.pages.dev

View logs

@PAMulligan PAMulligan merged commit b487dcf into main May 8, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unit and integration tests with Vitest + React Testing Library

1 participant